//package com.shoulder.ssh.factory;
//
//import com.jcraft.jsch.ChannelShell;
//import com.jcraft.jsch.JSch;
//import com.jcraft.jsch.Session;
//import com.shoulder.core.exception.BizException;
//import com.shoulder.ssh.properties.SSHProperties;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.pool2.PooledObject;
//import org.apache.commons.pool2.PooledObjectFactory;
//import org.apache.commons.pool2.impl.DefaultPooledObject;
//
//import java.io.*;
//import java.util.Properties;
//
//@Slf4j
//@Data
//public class SessionFactory implements PooledObjectFactory<Session> {
//
//    private final SSHProperties sshProperties;
//
//    @Override
//    public void activateObject(PooledObject<Session> pooledObject) throws Exception {
//        log.info("activate channel shell");
//    }
//
//    @Override
//    public void destroyObject(PooledObject<Session> pooledObject) throws Exception {
//        log.info("destroy ssh session");
//        Session session = pooledObject.getObject();
//        if (session.isConnected()) {
//            session.disconnect();
//        }
//    }
//
//    @Override
//    public PooledObject<Session> makeObject() throws Exception {
//        log.info("make ssh object session ");
//        try {
//            JSch jsch = new JSch();
//            Session session = jsch.getSession(sshProperties.getUsername(), sshProperties.getHost(), sshProperties.getPort());
//            session.setPassword(sshProperties.getPassword());
//            Properties sshConfig = new Properties();
//            sshConfig.put("StrictHostKeyChecking", sshProperties.getStrictHostKeyChecking());
//            session.setConfig(sshConfig);
//            session.connect(sshProperties.getTimeout());
//            return new DefaultPooledObject<>(session);
//        } catch (Exception e) {
//            throw new BizException("连接Shell失败");
//        }
//
//    }
//
//    @Override
//    public void passivateObject(PooledObject<Session> pooledObject) throws Exception {
//
//    }
//
//    @Override
//    public boolean validateObject(PooledObject<Session> pooledObject) {
//        log.info("validate ssh session");
//        Session session = pooledObject.getObject();
//        return session.isConnected();
//    }
//}
